import tool from '../tool'
import util from '_util/index'
import logic from '_logic'
import in_array from 'in_array'


export default{
  detailShowFields(){
    let tmp= [
          'id#ID', 'tail_status#跟进状态', 'order_id#主订单', 'pid#商品', 'attr_name#商品规格', 'pnum#数目', 'pay_money#支付金额', 'pay_platform#支付平台', 'remark#备注', 'status#状态', 'contact_info#联系人信息', 'iden_info#客人信息', 'address_info#收货信息', 'create_dt#创建时间', 'target_date#出行时间', 'update_dt#更新时间'
        ];
    return tmp;
  },
  get_chunked(_this){
    let tmp = [];
    let midFields = ['remark','contact_info','iden_info','address_info'];
    // let items = util.deepCopy(_this.items);
    let items = _this.items.filter(item=>item);
    let removed=_.remove(items, (item) => {
      let rs= in_array(item.field, midFields);
      return rs;
    });
    let leftNum = Math.ceil(items.length / 5 * 4);
    let chunked= _.chunk(items, leftNum);
    if(chunked) {
      tmp[0]= chunked[0];
      tmp[1]= _.concat(removed,chunked[1]);
      // tmp[2]= chunked[1];
      tmp[2]= null;
    }
    return tmp;
  },
  showPopDetail(_this,id){
    let eventVue = util.store.get(_this,'eventVue');
    let option = {
      detail_id: id
    };
    eventVue.$emit('showPopDetail',option);
  },
  get_detail_info(_this,id){
    if(id){
      this.showFields = this.detailShowFields();

      let eventVue = util.store.get(_this,'eventVue');
      eventVue.$emit('getDetailById',id);
      _this.items_all=util.store.getResult(_this, 'getDetailById');

      _this.items = [];
      _this.showFields.forEach(field=> {
        let obj = _this.items_all.find(item=> {
          let tmp = `${item.field}#${item.title}`;
          return tmp == field;
        });
        _this.items.push(obj);
      });

    }
  },
};